﻿namespace OperationFactory
{
    /// <summary>
    /// 工厂
    /// 计算简单工厂类(根据参数创建想要具体实例)
    /// </summary>
    public class Operation_Factory
    {
        /// <summary>
        /// 创建计算类
        /// </summary>
        /// <param name="operate">+、-、*、/</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static Operation createOperate(string operate) 
        {
            Operation oper;
            switch (operate)
            {
                case "+":
                    oper = new OperationAdd();
                    break;
                case "-":
                    oper = new OperationSub();
                    break;
                case "*":
                    oper = new OperationMul();
                    break;
                case "/":
                     oper = new OperationDiv();
                    break;
                default:
                    throw new ArgumentException("参数不合法.");
            }
            return oper;
        }
    }
}
